"use strict";
cc._RF.push(module, '1bc20ctx7ZHxY2esMDrK6cg', 'GyroscopeMgr');
// scripts/Game/GyroscopeMgr.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
//电子邮件puhalskijsemen@gmail.com
//源码网站 开vpn全局模式打开 http://web3incubators.com/
//电报https://t.me/gamecode999
//网页客服 http://web3incubators.com/kefu.html
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var GyroscopeMgr = /** @class */ (function (_super) {
    __extends(GyroscopeMgr, _super);
    function GyroscopeMgr() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    /**
     * 开始监听陀螺仪
     * @param GyriFun(res)  res：
     * {
        x	number	x 轴的角速度
        y	number	y 轴的角速度
        z	number	z 轴的角速度
        h5 没有以下属性 需要自己算
        roll	number	方位角，围绕 z 轴旋转角度
        pitch	number	俯仰角，围绕 x 轴旋转角度
        yaw	number	倾侧角，围绕 y 轴旋转角度}
     */
    GyroscopeMgr.startGyroscope = function (GyriFun) {
        switch (cc.sys.platform) {
            case cc.sys.WECHAT_GAME_SUB:
            case cc.sys.WECHAT_GAME: {
                window["wx"].startGyroscope({
                    interval: 'game',
                    success: function () { console.log("调用陀螺仪成功！"); },
                    fail: function () { console.log("调用陀螺仪失败！"); },
                    complete: function () { console.log("尝试调用陀螺仪！"); }
                });
                window["wx"].onGyroscopeChange(function (res) {
                    GyriFun && GyriFun(res);
                });
                break;
            }
            case cc.sys.BYTEDANCE_GAME:
            case cc.sys.BYTEDANCE_GAME_SUB: {
                window["tt"].startGyroscope({
                    interval: 20,
                    success: function () { console.log("调用陀螺仪成功!"); },
                    fail: function (res) { console.log(res.errMsg, "调用陀螺仪失败！"); },
                    complete: function () { console.log("尝试调用陀螺仪！"); }
                });
                window["tt"].onGyroscopeChange(function (res) {
                    GyriFun && GyriFun(res);
                });
                break;
            }
            case cc.sys.VIVO_GAME: {
                //TODO vivo陀螺仪  vivo没有陀螺仪...
                break;
            }
            case cc.sys.OPPO_GAME: {
                window['qg'].startGyroscope({
                    interval: 'game',
                    success: function (res) { console.log(res); },
                    fail: function (err) { console.log(err); },
                    complete: function () { }
                });
                break;
            }
            default: {
                if (cc.sys.isNative) {
                    //TODO 
                }
                else {
                    if (cc.sys.platform == 3 || cc.sys.platform == 4) {
                        //TODO 快手陀螺仪  快手没有陀螺仪...
                    }
                    else {
                        this.GyoscopeFun = function (res) {
                            var data = {};
                            data.x = res.alpha;
                            data.y = res.beta;
                            data.z = res.gamma;
                            GyriFun && GyriFun(data);
                        };
                        window.addEventListener('deviceorientation', this.GyoscopeFun, false);
                    }
                }
                break;
            }
        }
    };
    /**
     * 停用陀螺仪
     */
    GyroscopeMgr.stopGyroscope = function () {
        switch (cc.sys.platform) {
            case cc.sys.WECHAT_GAME_SUB:
            case cc.sys.WECHAT_GAME: {
                window["wx"].stopGyroscope({
                    success: function () { console.log("停用陀螺仪成功！"); },
                    fail: function () { console.log("停用陀螺仪失败！"); },
                    complete: function () { console.log("尝试停用陀螺仪！"); }
                });
                window['wx'].offGyroscopeChange();
                break;
            }
            case cc.sys.BYTEDANCE_GAME:
            case cc.sys.BYTEDANCE_GAME_SUB: {
                window["tt"].stopGyroscope({
                    success: function () { console.log("停用陀螺仪成功！"); },
                    fail: function () { console.log("停用陀螺仪失败！"); },
                    complete: function () { console.log("尝试停用陀螺仪！"); }
                });
                window['tt'].offGyroscopeChange();
                break;
            }
            case cc.sys.VIVO_GAME: {
                break;
            }
            case cc.sys.OPPO_GAME: {
                window['qg'].stopGyroscope({
                    success: function (res) { console.log("陀螺仪停用成功", res); },
                    fail: function (err) { console.log("陀螺仪停用失败", err); },
                    complete: function () { console.log("尝试停用陀螺仪！"); }
                });
                window['qg'].offGyroscopeChange();
                break;
            }
            default: {
                if (cc.sys.isNative) {
                }
                else {
                    if (cc.sys.platform == 3 || cc.sys.platform == 4) {
                    }
                    else {
                        window.removeEventListener('deviceorientation', this.GyoscopeFun, false);
                    }
                }
                break;
            }
        }
    };
    GyroscopeMgr.GyoscopeFun = null;
    GyroscopeMgr = __decorate([
        ccclass
    ], GyroscopeMgr);
    return GyroscopeMgr;
}(cc.Component));
exports.default = GyroscopeMgr;

cc._RF.pop();